/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023.
 * Description: mbigen linear process
 * Author: yangzhuohao
 * Create: 2023-10-25
 */

#include <linux/hal/irq-mbigen.h>
#include "../../drivers/hal/internal_linear.h"

#ifdef CONFIG_HISILICON_IRQ_MBIGEN
static int irq_domain_alloc_irqs_for_mbigen_linear(struct irq_domain *domain,
	struct irq_fwspec *fwspec)
{
	int virq;
	struct irq_data *irqdata = NULL;

	virq = irq_domain_alloc_irqs_locked(domain, fwspec->param[2], 1,
			NUMA_NO_NODE, fwspec, false, NULL);
	if (virq >= 8192) {
		irqdata = irq_domain_get_irq_data(irq_default_domain, virq);
		if (irqdata != NULL)
			mbigen_irq[irqdata->hwirq - HI1382_LPI_SPI_DIFF].virq = virq;
	}
	return virq;
}

#else
static inline int irq_domain_alloc_irqs_for_mbigen_linear(
	struct irq_domain *domain, struct irq_fwspec *fwspec)
{
	/* means alloc failed */
	return 0;
}
#endif

int irq_domain_alloc_irqs_for_linear(struct irq_domain *domain,
	struct irq_fwspec *fwspec, irq_hw_number_t hwirq)
{
	int virq;
	irq_domain_find_parent_t irq_domain_find_parent;

	if (irq_domain_is_mbigen(domain->ops)) {
		virq = irq_domain_alloc_irqs_for_mbigen_linear(domain, fwspec);
	} else {
		irq_domain_find_parent = get_irq_domain_find_parent();
		if (irq_domain_find_parent)
			hwirq = irq_domain_find_parent(domain, hwirq);
		virq = irq_domain_alloc_irqs_locked(domain, hwirq, 1,
			NUMA_NO_NODE, fwspec,
			false, NULL);
	}
	return virq;
}

